<?php

// 本类由系统自动生成，仅供测试用途
class IndexAction extends Action
{

    public function index()
    {
        //$this->show('<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} body{ background: #fff; font-family: "微软雅黑"; color: #333;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.8em; font-size: 36px }</style><div style="padding: 24px 48px;"> <h1>:)</h1><p>欢迎使用 <b>ThinkPHP</b>！</p></div><script type="text/javascript" src="http://tajs.qq.com/stats?sId=9347272" charset="UTF-8"></script>','utf-8');

//    $db=M('user');
//    $result=$db->select();
//        dump($result);
//echo U("Index/add",array('uid'=>fuck,'uid2'=>2),"",0,true);
        //      echo C('MY_USERNAME');
        $this->display();


    }

    public function add()
    {
        dump(I('uid'));
        echo '这是index方法里的add';
    }

    public function Login()
    {
        if (!IS_AJAX) {
            halt("页面不存在请返回主页");

        }
        $verifycode = $_SESSION['verify'];
        $loginverify = md5(I('verify'));


        if ($loginverify != $verifycode) {

            $this->ajaxReturn(array('status' => 'error', 'msg' => '验证码错误'));
            return;
        }

        $username = I('username');
        $userpwd = I("userpwd");


        $con['username'] = $username;
        $con['userpwd'] = $userpwd;
        $result = M('user')->where($con)->find();


        if ($result) {
            $_SESSION['uid']=$result['Id'];
            $_SESSION['username']=$result['username'];
            $_SESSION['logintime']=time();

            $this->ajaxReturn(array('status' => 'ok', 'msg' => '登陆成功!'));

        } else {
            $this->ajaxReturn(array('status' => 'error', 'msg' => '用户验证失败'));
        }


    }

    public function Loginout()
    {
        session_unset();
        session_destroy();
        $this->redirect('Index');

}
    public function verify()
    {
        import('ORG.Util.Image');
        Image::buildImageVerify();
    }
    public function getUserInfo(){
        $userinfo['uid']= $_SESSION['uid'];
        $userinfo['username']= $_SESSION['username'];
        $userinfo['logintime']= $_SESSION['logintime'];

        $this->ajaxReturn($userinfo);

    }
}